package com.yilin.platform.entity.user.deserialize;

import javax.persistence.Column;
import java.io.BufferedReader;
import java.io.FileReader;

public class HatchAlipay {
    private String aliPayBackUrl;//返回通知地址

    //---------------貨主端---------------------------
    private String shipperAlipayAppId;//APPID
    private String shipperPId;//支付宝合作者商户PID
    private String shipperUrlScheme;//IOS跳转连接
    private String shipperAppPrivateKeyUrl;//RSA私钥
    private String shipperAppPublicKeyUrl;////设置应用公钥证书路径
    private String shipperAlipayCertFolderUrl;//设置支付宝公钥证书路径
    private String shipperAlipayRootCertFolderUrl;//设置支付宝根证书路径


    //---------------司机端---------------------------
    private String truckerAlipayAppId;//APPID
    private String truckerPId;//支付宝合作者商户PID
    private String truckerUrlScheme;//IOS跳转连接
    private String truckerAppPrivateKeyUrl;//RSA私钥
    private String truckerAppPublicKeyUrl;///设置应用公钥证书路径
    private String truckerAlipayCertFolderUrl;//设置支付宝公钥证书路径
    private String truckerAlipayRootCertFolderUrl;//设置支付宝根证书路径

    public String getAliPayBackUrl() {
        return aliPayBackUrl;
    }

    public String getAlipayAppId(String userType) {
        if ("shipperUser".equals(userType)) {
            return this.shipperAlipayAppId;
        } else if ("truckerUser".equals(userType)) {
            return this.truckerAlipayAppId;
        } else {
            return null;
        }
    }

    public String getPid(String userType) {
        if ("shipperUser".equals(userType)) {
            return this.shipperPId;
        } else if ("truckerUser".equals(userType)) {
            return this.truckerPId;
        } else {
            return null;
        }
    }

    public String getUrlScheme(String userType) {
        if ("shipperUser".equals(userType)) {
            return this.shipperUrlScheme;
        } else if ("truckerUser".equals(userType)) {
            return this.truckerUrlScheme;
        } else {
            return null;
        }
    }

    public String getRsa2PrivateKey(String userType) {
        if ("shipperUser".equals(userType)) {
            return readFileToString(this.shipperAppPrivateKeyUrl);
        } else if ("truckerUser".equals(userType)) {
            return readFileToString(this.truckerAppPrivateKeyUrl);
        } else {
            return null;
        }
    }

    public String getRsa2PublicKeyPath(String userType) {
        if ("shipperUser".equals(userType)) {
            return this.shipperAppPublicKeyUrl;
        } else if ("truckerUser".equals(userType)) {
            return this.truckerAppPublicKeyUrl;
        } else {
            return null;
        }
    }

    public String getRsa2CertFolderPath(String userType) {
        if ("shipperUser".equals(userType)) {
            return this.shipperAlipayCertFolderUrl;
        } else if ("truckerUser".equals(userType)) {
            return this.truckerAlipayCertFolderUrl;
        } else {
            return null;
        }
    }

    public String getRsa2RootCertFolderPath(String userType) {
        if ("shipperUser".equals(userType)) {
            return this.shipperAlipayRootCertFolderUrl;
        } else if ("truckerUser".equals(userType)) {
            return this.truckerAlipayRootCertFolderUrl;
        } else {
            return null;
        }
    }
    private  String readFileToString(String filePath) {
        StringBuilder content = new StringBuilder();

        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = reader.readLine()) != null) {
                content.append(line).append("\n"); // 将每行内容拼接到字符串
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return content.toString();
    }
}
